package com.example.mybatisplusservice.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.mybatisplusservice.User;
import com.example.mybatisplusservice.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * @author wuxinxin
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    @GetMapping("/one/{userId}")
    public List<User> getOne(@PathVariable Integer userId){
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(Thread.currentThread().getName()+"----------打印线程名称");
        return userService.getOne(userId);
    }

    @GetMapping
    public IPage<User> list(Integer page, Integer pageSize){
        return userService.list(page,pageSize);
    }


    @GetMapping("/list2")
    public IPage<User> list2(Integer page, Integer pageSize,Integer childrenId){
        try {
            Thread.sleep(10000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return userService.list2(page,pageSize,childrenId);
    }

    @PostMapping
    public void addUser() throws InterruptedException {
        userService.addUser();
    }


    @PostMapping("/testTransactional1")
    public void testTransactional1() throws InterruptedException {
        userService.testTransactional1();
    }

    @PostMapping("/testTransactional2")
    public void testTransactional2() throws InterruptedException {
        userService.testTransactional2();
    }
}
